#!/bin/bash

setup_java()
{
  echo_start "$1 ... ..."

  confirm_operate "Install java on local host"
  if [ $? -eq 0 ]; then
    # 本机安装java
    rpm -ivh $XDIR/packages/jdk-8u121-linux-x64.rpm
    if [ $? -ne 0 ]; then die "install jdk fail."; fi
    echo_success "Install java on local host done."

    echo_passed "$1 local  install done."
  else
    echo_passed "$1 SKIP local  install"
  fi

  confirm_operate "Install java on remote host"
  if [ $? -eq 0 ]; then
    # 远程安装java
    local value_arr=($HYREN_ALLHOSTS)
    for i in ${value_arr[@]}; do
      echo ""
      echo_info "install java on ${i} ... ..."
      # 如果本机在ALLHOSTS中，则跳过
      if [ "${i}" == "$HYRENSERV_HOSTNAME" ]; then echo_warn "skip ${i}"; continue; fi
      scp $XDIR/packages/jdk-8u121-linux-x64.rpm  root@${i}:/tmp/ >> $SETUP_LOGFILE || { die "scp jdk to [${i}] fail."; }
      ssh -o StrictHostKeyChecking=no $i "rpm -ivh /tmp/jdk-8u121-linux-x64.rpm" || { die "install jdk fail on ${i}."; }
    done
    echo_success "Install java on remote host done."
    
    echo_passed "$1 remote install done."
  else
    echo_passed "$1 SKIP remote install"
  fi
}